//
//  THJHejinMapVC.m
//  THJXHW
//
//  Created by 河南德艺 on 17/6/16.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJHejinMapVC.h"
#import <WebKit/WebKit.h>

@interface THJHejinMapVC ()<WKUIDelegate, WKNavigationDelegate>
{
    WKWebView * _webView;
    UISegmentedControl * _segment;
}

@end

@implementation THJHejinMapVC
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    _segment.hidden = YES;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    _segment.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setTitleSegmnet];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"合金地图"];
    }else{
        [self setNavBarWithTitle:@"合金地图"];
    }
    [self setBottomView];
    _webView = [[WKWebView alloc]init];

     _webView.frame = CGRectMake(0, NavbarHeight, ScreenWidth, ScreenHeight-NavbarHeight);
   
     [self.view addSubview:_webView];
    _webView.UIDelegate = self;
    _webView.navigationDelegate = self;
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.thjb.net/huodong/webmap/Forecast.html?type=1"]]];
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    //Do any additional setup after loading the view.
}
-(void)setBottomView{
    UIView * view = [UIView new];
    view.frame = CGRectMake(0, ScreenHeight-49, ScreenWidth, 49);
    view.backgroundColor = SingleColor(whiteColor);
    [self.view addSubview:view];
}
-(void)setTitleSegmnet{
    NSArray *array = [NSArray arrayWithObjects:@"合金地图",@"企业地图", nil];
    //初始化UISegmentedControl
    _segment = [[UISegmentedControl alloc]initWithItems:array];
    //设置frame
    _segment.tintColor = COLOR(254, 216, 216, 1.0);
    _segment.frame = CGRectMake((ScreenWidth - 160)/2, 10, 160, 30);
    //添加到视图
    [_segment addTarget:self action:@selector(segmentedChanged:) forControlEvents:UIControlEventValueChanged];
    _segment.selectedSegmentIndex = 0;
    [self.navigationController.navigationBar addSubview:_segment];
}

-(void)segmentedChanged:(UISegmentedControl*)segment{
    if (segment.selectedSegmentIndex == 0) {
         [MBProgressHUD showMessage:@"正在加载" toView:self.view];
         [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.thjb.net/huodong/webmap/Forecast.html?type=1"]]];
    }else{
        [MBProgressHUD showMessage:@"正在加载" toView:self.view];
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.thjb.net/huodong/hjb_map/index.html?type=3&from=singlemessage&isappinstalled=0"]]];
    }
    
}
//页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
//页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
    [self HUDShowMsg:@"加载失败" AfterDelayDimiss:2];
}
@end
